﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace Redbrick.Silverlight.Controls
{
	public class PlaceableItemsControl : ItemsControl
	{
		protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
		{
			FrameworkElement contentItem = element as FrameworkElement;
			
            //TODO: find out if the panel is a canvas or grid (etc.) and set x/y binding accordingly
            Binding leftBinding = new Binding("X");
			Binding topBinding = new Binding("Y");
            contentItem.SetBinding(Canvas.LeftProperty, leftBinding);
            contentItem.SetBinding(Canvas.TopProperty, topBinding);

            Binding colBinding = new Binding("X");
            Binding rowBinding = new Binding("Y");
            contentItem.SetBinding(Grid.ColumnProperty, colBinding);
            contentItem.SetBinding(Grid.RowProperty, rowBinding);
			
            base.PrepareContainerForItemOverride(element, item);
		}

        protected override DependencyObject GetContainerForItemOverride()
        {
            DependencyObject container = base.GetContainerForItemOverride();
            return container;
        }
	}
}
